package com.ljy.my_study.leetcode.打家劫舍III;

import com.ljy.my_study.util.TreeNodeUtil;
import com.ljy.my_study.util.TreeNodeUtil.*;

/**
 * @author lijunying
 * @date 2020/8/5 11:34
 */
public class TestMain2 {

    public int rob(TreeNode root) {
        int[] array=dfs(root);
        return Math.max(array[0],array[1]);
    }

    public int[] dfs(TreeNode node) {
        if(node==null){
            return new int[2];
        }
        int[] l=dfs(node.left);
        int[] r=dfs(node.right);
        int selected=node.val+l[1]+r[1];
        int notSelected=Math.max(l[0],l[1])+Math.max(r[0],r[1]);
        return new int[]{selected,notSelected};
    }

}
